package com.ys.web.mobao.mapper;

import com.ys.base.BaseDao;
import com.ys.web.pay.model.WithdrawRecord;
import com.ys.web.pay.model.WithdrawRecordWait;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface MobaoWithholdingMapper extends BaseDao {
    @Select("select count(1) from withdraw_record_wait where user_id=#{uid} and withdraw_status='2'")
    int getUserWhiteByUid(@Param("uid")long uid);
    void saveWithdrawRecord(WithdrawRecord record);
    void saveWithdrawRecordWait(WithdrawRecordWait record);

    @Select("select * from withdraw_record where order_no=#{orderId}")
    WithdrawRecord getWithdrawRecordByOrderId(String orderId);

    @Select("select * from withdraw_record_wait where id=#{id}")
    WithdrawRecordWait getWithdrawRecordWaitById(String id);

    @Update("update withdraw_record set withdraw_status=#{withdrawStatus},day_key=#{dayKey},remark=#{remark} where id=#{id} and withdraw_status='1'")
    int updateWithdrawRecordByOrderId(WithdrawRecord record);
    @Update("update withdraw_record set withdraw_status=#{withdrawStatus},day_key=#{dayKey},remark=#{remark} where id=#{id} and withdraw_status='6'")
    int updateWithdrawRecordTask(WithdrawRecord record);
    @Update("update withdraw_record set withdraw_status=#{withdrawStatus} where id=#{id} and withdraw_status='4'")
    int updateWithdrawRecordWaitByOrderId(WithdrawRecord record);

    @Select("select id,user_id,amount,order_no from withdraw_record where withdraw_status='1' and raw_add_time < date_add(NOW(),interval -10 minute)")
    List<WithdrawRecord> getWithdrawRecordListByTime();

    @Select("select count(id) from withdraw_record_wait where user_id=#{uid} and withdraw_status='2'")
    int getWithdrawRecordWaitCountByUid(@Param("uid")long uid);

    int withholdingSuccess(@Param("id")long id,@Param("status") String status);
    int withholdingStatus(@Param("id")long id,@Param("status") String status);
    int insertSxf(@Param("requestNo")String requestNo,@Param("uid")long uid, @Param("orderNo")String orderNo,
                  @Param("amount") long amount,
                  @Param("fee") long fee,
                  @Param("dayTime")long dayTime,
                  @Param("status")int status,
                  @Param("remark")String remark);
    int insertSxfMb(@Param("requestNo")String requestNo,@Param("uid")long uid, @Param("orderNo")String orderNo,
                  @Param("amount") long amount,
                  @Param("fee") long fee,
                  @Param("dayTime")long dayTime,
                  @Param("status")int status,
                  @Param("remark")String remark);
    int updateSxf(@Param("orderNo")String orderNo, @Param("status")int status, @Param("remark")String remark);

    List<WithdrawRecordWait> getWithdrawRecordListTask(@Param("dayTime") long dayTime);

    int orderOutNoUpdate(@Param("id")long id, @Param("orderOutNo")String orderOutNo,
                         @Param("payFundOrderId")String payFundOrderId,@Param("status")String status,@Param("dayKey")int dayKey);

    int withholdingErrMsgStatus(@Param("id")long id,@Param("status") String status, @Param("errMsg")String errMsg);

    @Update("update withdraw_record set withdraw_status=8 where id=#{id} and withdraw_status='6'")
    int updateWithdrawRecordStatus(WithdrawRecord withdrawRecord);

    @Update("update withdraw_record set withdraw_status=#{withdrawStatus},day_key=#{dayKey},remark=#{remark},orderOutNo=#{orderOutNo} where id=#{id} and withdraw_status='8'")
    int updateWithdrawRecordStatusTask(WithdrawRecord record);

    @Select("select count(id) from withdraw_record where user_id=#{uid} and withdraw_status IN('1','6') AND payChannel=1 ")
    int getWithdrawNum(@Param("uid")long uid);
}
